package disanzhou;

import java.util.Random;
import java.util.Scanner;

public class text4 {
    public static void main(String[] args) {
        System.out.println("随机点名器");
        //假设班级内有三名同学
        String[]Class=addStudentName(3);

        printStudentName(Class);

        randomStudentName(Class);

    }

    public static String[] addStudentName(int n){
        String[] Class=new String[n];
        Scanner sc=new Scanner(System.in);
        String tmp="";
        //存入班里内同学姓名
        for(int i=0;i<Class.length;i++){
            System.out.println("储存第"+(i+1)+"个姓名:");
            tmp=sc.next();
            Class[i]=tmp;
        }
        return Class;
    }

    //总览全班同学名字
    public static void printStudentName(String[] Class) {
        for(int i=0;i<Class.length;i++)
        {
            System.out.println("第"+(i+1)+"个学生姓名"+Class[i]);
        }
    }

    public static void randomStudentName(String[] Class) {
        Random r=new Random();
        int suiji=r.nextInt(Class.length);
        System.out.println("被点名的同学是"+Class[suiji]);
    }

}
